@Test
public void update() {
- assertThatThrownBy(() -> state.update(new PdpUpdate()))
+ PdpUpdate update = new PdpUpdate();
+ assertThatThrownBy(() -> state.update(update))
.isInstanceOf(UnsupportedOperationException.class);
}
@Test
public void stateChange() {
- assertThatThrownBy(() -> state.stateChange(new PdpStateChange()))
+ PdpStateChange change = new PdpStateChange();
+ assertThatThrownBy(() -> state.stateChange(change))
.isInstanceOf(UnsupportedOperationException.class);
}
@Test
public void changeState() {
- assertThatThrownBy(() -> state.transitionToState(new LifecycleStateActive(new LifecycleFsm())))
+ LifecycleStateActive active = new LifecycleStateActive(new LifecycleFsm());
+ assertThatThrownBy(() -> state.transitionToState(active))
.isInstanceOf(UnsupportedOperationException.class);
}
}
@Test
public void testPublish() throws PoolingFeatureException {
// cannot publish before starting
- assertThatThrownBy(() -> mgr.publish(MSG)).as("publish,pre");
+ assertThatThrownBy(() -> mgr.publish(MSG)).as("publish,pre").isInstanceOf(PoolingFeatureException.class);
mgr.startPublisher();
// stop and verify we can no longer publish
mgr.stopPublisher(0);
- assertThatThrownBy(() -> mgr.publish(MSG)).as("publish,stopped");
+ assertThatThrownBy(() -> mgr.publish(MSG)).as("publish,stopped").isInstanceOf(PoolingFeatureException.class);
}
@Test(expected = PoolingFeatureException.class)
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-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.
}
}
+ /*
+ * This test should only be run manually, after configuring all of the fields,
+ * thus it is ignored.
+ */
@Ignore
@Test
- public void test_SingleHost() throws Exception {
+ public void test_SingleHost() throws Exception { // NOSONAR
run(70, 1);
}
+ /*
+ * This test should only be run manually, after configuring all of the fields,
+ * thus it is ignored.
+ */
@Ignore
@Test
- public void test_TwoHosts() throws Exception {
+ public void test_TwoHosts() throws Exception { // NOSONAR
run(200, 2);
}
+ /*
+ * This test should only be run manually, after configuring all of the fields,
+ * thus it is ignored.
+ */
@Ignore
@Test
- public void test_ThreeHosts() throws Exception {
+ public void test_ThreeHosts() throws Exception { // NOSONAR
run(200, 3);
}
assertEquals(msg.getChannel(), decoded.getChannel());
// invalid subclass when encoding
- assertThatThrownBy(() -> ser.encodeMsg(new Message() {})).isInstanceOf(JsonParseException.class)
+ Message msg2 = new Message() {};
+ assertThatThrownBy(() -> ser.encodeMsg(msg2)).isInstanceOf(JsonParseException.class)
.hasMessageContaining("cannot serialize");
// missing type when decoding
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 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.
String[] arr = captureHostArray();
- assertNotSame(arr, HOST_ARR3);
+ assertNotSame(HOST_ARR3, arr);
assertEquals(Arrays.asList(HOST_ARR3), Arrays.asList(arr));
}
}
}
+ session.removePolicySession();
logger.info("PersistentThreadModel completed");
}
}
// return adjunct on next call
when(polcont.getAdjunct(any())).thenReturn(adjcap.getValue());
- try {
- doThrow(new IllegalArgumentException(EXPECTED)).when(emf).close();
-
- feat.destroyKieSession(polsess);
- fail(MISSING_EXCEPTION);
-
- } catch (IllegalArgumentException ex) {
- logger.trace(EXPECTED, ex);
- }
+ IllegalArgumentException exception = new IllegalArgumentException(EXPECTED);
+ doThrow(exception).when(emf).close();
+ assertThatCode(() -> feat.destroyKieSession(polsess)).isEqualTo(exception);
verify(bds, times(2)).close();
}
// return adjunct on next call
when(polcont.getAdjunct(any())).thenReturn(adjcap.getValue());
- try {
- doThrow(new SQLException(EXPECTED)).when(bds).close();
-
- feat.destroyKieSession(polsess);
- fail(MISSING_EXCEPTION);
-
- } catch (PersistenceFeatureException ex) {
- logger.trace(EXPECTED, ex);
- }
+ SQLException cause = new SQLException(EXPECTED);
+ doThrow(cause).when(bds).close();
+ assertThatCode(() -> feat.destroyKieSession(polsess)).isInstanceOf(PersistenceFeatureException.class)
+ .hasCause(cause);
}
/**
package org.onap.policy.drools.statemanagement.test;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
logger.debug("avail = {}", avail);
logger.debug("standby = {}", standby);
- assertTrue("Admin state not unlocked after initialization", admin.equals(StateManagement.UNLOCKED));
- assertTrue("Operational state not enabled after initialization", oper.equals(StateManagement.ENABLED));
+ assertEquals("Admin state not unlocked after initialization", StateManagement.UNLOCKED, admin);
+ assertEquals("Operational state not enabled after initialization", StateManagement.ENABLED, oper);
try {
stateManagementFeature.disableFailed();
logger.debug("avail = {}", avail);
logger.debug("standby = {}", standby);
- assertTrue("Operational state not disabled after disableFailed()", oper.equals(StateManagement.DISABLED));
- assertTrue("Availability status not failed after disableFailed()", avail.equals(StateManagement.FAILED));
+ assertEquals("Operational state not disabled after disableFailed()", StateManagement.DISABLED, oper);
+ assertEquals("Availability status not failed after disableFailed()", StateManagement.FAILED, avail);
try {
logger.debug("avail = {}", avail);
logger.debug("standby = {}", standby);
- assertTrue("Standby status not coldstandby after promote()", standby.equals(StateManagement.COLD_STANDBY));
+ assertEquals("Standby status not coldstandby after promote()", StateManagement.COLD_STANDBY, standby);
/* *************Repository Audit Test. ************* */
logger.debug("\n\ntestStateManagementOperation: Repository Audit\n\n");
policySess.set(this);
}
+ /**
+ * Unset this 'PolicySession' instance as the one associated with the
+ * currently-running thread.
+ */
+ public void removePolicySession() {
+ if (policySess.get() == this) {
+ policySess.remove();
+ }
+ }
+
/**
* Get current session.
*
logger.error("startThread error in kieSession1.fireUntilHalt", e);
}
}
+
+ session.removePolicySession();
logger.info("fireUntilHalt() returned");
}
}
}
@Test
- public void testSetPolicySession_testGetCurrentSession() {
+ public void testSetPolicySession_testGetCurrentSession_testRemovePolicySession() {
PolicySession sess2 = new PolicySession(MY_NAME + "-b", container, kie);
session.setPolicySession();
sess2.setPolicySession();
assertEquals(sess2, PolicySession.getCurrentSession());
+
+ // remove a different session - should be unchanged
+ session.removePolicySession();
+ assertEquals(sess2, PolicySession.getCurrentSession());
+
+ // remove the session
+ sess2.removePolicySession();
+ assertNull(PolicySession.getCurrentSession());
}
@Test
public class DomainPolicyTypesTest {
// Policy Types
- private static final String OPERATIONAL_DROOLS_POLICY_TYPE = "onap.policies.controlloop.operational.common.Drools";
private static final String NATIVE_DROOLS_POLICY_TYPE = "onap.policies.native.drools.Artifact";
- // Operational vCPE Policy
- private static final String OP_POLICY_NAME_VCPE = "operational.restart";
- private static final String VCPE_OPERATIONAL_DROOLS_POLICY_JSON =
- "policies/vCPE.policy.operational.input.tosca.json";
-
// Native Drools Policy
private static final String EXAMPLE_NATIVE_DROOLS_POLICY_NAME = "example";
private static final String EXAMPLE_NATIVE_DROOLS_POLICY_JSON =
ToscaServiceTemplate serviceTemplate = new StandardCoder().decode(policyJson, ToscaServiceTemplate.class);
return serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyName);
}
-
- private String getExamplesPolicyString(String resourcePath, String policyName) throws CoderException {
- return nonValCoder.encode(getExamplesPolicy(resourcePath, policyName));
- }
-}
\ No newline at end of file
+}
.flush();
logger.warn(
LoggerUtil.TRANSACTION_LOG_MARKER,
- "Main: cannot start {} (bad state) because of {}",
- PolicyEngineConstants.getManager(),
- e.getMessage(),
- e);
+ "Main: cannot start {} (bad state)",
+ PolicyEngineConstants.getManager());
throw new PolicyDroolsPdpRuntimeException(
String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DROOLS_PDP), e);
} catch (final Exception e) {
.flush();
logger.warn(
LoggerUtil.TRANSACTION_LOG_MARKER,
- "Main: cannot start {} because of {}",
- PolicyEngineConstants.getManager(),
- e.getMessage(),
- e);
+ "Main: cannot start {}",
+ PolicyEngineConstants.getManager());
throw new PolicyDroolsPdpRuntimeException(
String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DROOLS_PDP), e);
}
.flush();
logger.error(
LoggerUtil.TRANSACTION_LOG_MARKER,
- "Main: cannot instantiate policy-controller {} because of {}",
- controllerName,
- e.getMessage(),
- e);
+ "Main: cannot instantiate policy-controller {}",
+ controllerName);
throw new PolicyDroolsPdpRuntimeException(
String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DROOLS_PDP), e);
} catch (final LinkageError e) {
.flush();
logger.warn(
LoggerUtil.TRANSACTION_LOG_MARKER,
- "Main: cannot instantiate policy-controller {} (linkage) because of {}",
- controllerName,
- e.getMessage(),
- e);
+ "Main: cannot instantiate policy-controller {} (linkage)",
+ controllerName);
throw new PolicyDroolsPdpRuntimeException(
String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DROOLS_PDP), e);
}
ControllerConfiguration controllerConfig = new ControllerConfiguration(NAME, OPERATION, DROOLS_CONFIG);
- assertEquals(controllerConfig, controllerConfig);
+ assertEquals(controllerConfig, (Object) controllerConfig);
assertNotEquals(controllerConfig, new Object());
ControllerConfiguration controllerConfig2 = new ControllerConfiguration();
additionalProperties.put(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE);
final DroolsConfiguration droolsConfig = new DroolsConfiguration(ARTIFACT, GROUPID, VERSION);
- assertEquals(droolsConfig, droolsConfig);
+ assertEquals(droolsConfig, (Object) droolsConfig);
droolsConfig.set(ARTIFACT_ID_STRING, "foobar");
assertEquals("foobar", droolsConfig.get(ARTIFACT_ID_STRING));
drools.set("version", VERSION);
drools.set(PROPERTY1, VALUE1);
- assertEquals(drools, drools);
+ assertEquals(drools, (Object) drools);
assertNotEquals(drools, new Object());
logger.info("Drools HashCode {}", drools.hashCode());
controller.set("drools", drools);
controller.set(PROPERTY1, VALUE1);
- assertEquals(controller, controller);
+ assertEquals(controller, (Object) controller);
assertNotEquals(controller, new Object());
logger.info("Controller HashCode {}", controller.hashCode());
config.set("controllers", controllers);
config.set(PROPERTY1, VALUE1);
- assertEquals(config, config);
+ assertEquals(config, (Object) config);
assertNotEquals(config, new Object());
logger.info("Config HashCode {}", config.hashCode());
assertDomainPolicy(domainAPolicy);
domainAPolicy.getProperties().getNested().setNested1("");
- assertThatThrownBy(() -> domainMaker.conformance(policy1.getTypeIdentifier(), domainAPolicy))
+ ToscaPolicyTypeIdentifier ident1 = policy1.getTypeIdentifier();
+ assertThatThrownBy(() -> domainMaker.conformance(ident1, domainAPolicy))
.isInstanceOf(ValidationFailedException.class)
.hasMessageContaining("Pattern ^(.+)$ is not contained in text");
}
@Test
public void testConvertToSchema() {
+ ToscaPolicyType type = new ToscaPolicyType();
assertThatThrownBy(() -> domainMaker
- .convertToSchema(new ToscaPolicyType()))
+ .convertToSchema(type))
.isInstanceOf(UnsupportedOperationException.class);
}
assertEquals(trans.getInvocationId(), MDC.get(MdcTransactionConstants.INVOCATION_ID));
assertEquals(trans.timestamp(trans.getStartTime()), MDC.get(MdcTransactionConstants.BEGIN_TIMESTAMP));
assertEquals(trans.timestamp(trans.getEndTime()), MDC.get(MdcTransactionConstants.END_TIMESTAMP));
- assertNotEquals(trans.getElapsedTime(), MDC.get(MdcTransactionConstants.ELAPSED_TIME));
assertEquals(String.valueOf(Duration.between(trans.getStartTime(), trans.getEndTime()).toMillis()),
MDC.get(MdcTransactionConstants.ELAPSED_TIME));
assertEquals(trans.getServiceInstanceId(), MDC.get(MdcTransactionConstants.SERVICE_INSTANCE_ID));