<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>mockito-configuration</artifactId>
+ </dependency>
</dependencies>
<build>
JmxAttribute that = (JmxAttribute) o;
- if (attributeName != null ? !attributeName.equals(that.attributeName)
- : that.attributeName != null) {
+ if (!attributeName.equals(that.attributeName)) {
return false;
}
@Override
public int hashCode() {
- return attributeName != null ? attributeName.hashCode() : 0;
+ return attributeName.hashCode();
}
@Override
--- /dev/null
+package org.opendaylight.controller.config.api;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
+import org.opendaylight.yangtools.yang.binding.BaseIdentity;
+
+import javax.management.*;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.*;
+
+public class IdentityAttributeRefTest {
+
+ IdentityAttributeRef attr = new IdentityAttributeRef("attr");
+
+ @Test
+ public void testConstructor() throws Exception {
+ String param = new String("attr");
+ Assert.assertEquals(attr.getqNameOfIdentity(), param);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testConstructor2() throws Exception {
+ IdentityAttributeRef attr = new IdentityAttributeRef(null);
+ }
+
+ @Test
+ public void testHashCode() throws Exception {
+ Assert.assertEquals(attr.hashCode(), new String("attr").hashCode());
+ }
+
+ @Test
+ public void testEqual() throws Exception {
+ Assert.assertEquals(attr, attr);
+ }
+
+ @Test
+ public void testEqual2() throws Exception {
+ Assert.assertEquals(attr, new IdentityAttributeRef("attr"));
+ }
+
+ @Test
+ public void testNotEqual() throws Exception {
+ Assert.assertNotEquals(attr, new IdentityAttributeRef("different"));
+ }
+
+ @Test
+ public void testResolveIdentity() throws Exception {
+ DependencyResolver res = mock(DependencyResolver.class);
+ IdentityAttributeRef a = new IdentityAttributeRef("abcd");
+ doReturn(SubIdentity.class).when(res).resolveIdentity(a, Identity.class);
+ a.resolveIdentity(res, Identity.class);
+ verify(res).resolveIdentity(a, Identity.class);
+ }
+
+ @Test
+ public void testValidateIdentity() throws Exception {
+ DependencyResolver res = mock(DependencyResolver.class);
+ JmxAttribute jmxAttr = new JmxAttribute("abc");
+ doNothing().when(res).validateIdentity(attr, Identity.class, jmxAttr);
+ attr.validateIdentity(res, Identity.class, jmxAttr);
+ verify(res).validateIdentity(attr, Identity.class, jmxAttr);
+ }
+
+ static class Identity extends BaseIdentity {}
+
+ static class SubIdentity extends Identity {}
+}
--- /dev/null
+package org.opendaylight.controller.config.api;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class JmxAttributeTest {
+
+ @Test
+ public void testJmxAttribute() throws Exception {
+ JmxAttribute attr = new JmxAttribute("test");
+ assertEquals("test", attr.getAttributeName());
+ }
+
+ @Test
+ public void testToString() throws Exception {
+ JmxAttribute attr = new JmxAttribute("test");
+ assertEquals(attr.toString(), new JmxAttribute("test").toString());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testJmxAttributeInvalid() throws Exception {
+ JmxAttribute attr = new JmxAttribute(null);
+ }
+
+ @Test
+ public void testJmxAttributeEqual() throws Exception {
+ JmxAttribute a1 = new JmxAttribute("test_string");
+ JmxAttribute a2 = new JmxAttribute("test_string");
+ assertEquals(a1, a2);
+ }
+
+ @Test
+ public void testJmxAttributeNotEqual() throws Exception {
+ JmxAttribute a1 = new JmxAttribute("test_string");
+ JmxAttribute a2 = new JmxAttribute("different");
+ assertNotEquals(a1, a2);
+ }
+
+ @Test
+ public void testJmxAttributeEqual2() throws Exception {
+ JmxAttribute a1 = new JmxAttribute("test_string");
+ assertNotNull(a1);
+ }
+
+ @Test
+ public void testJmxAttributeHashCode() throws Exception {
+ JmxAttribute a1 = new JmxAttribute("test_string");
+ assertEquals(a1.hashCode(), new String("test_string").hashCode());
+ }
+}
package org.opendaylight.controller.config.api;
-import static org.junit.Assert.assertEquals;
+import java.nio.file.AccessDeniedException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import com.google.common.collect.Lists;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import javax.management.Query;
+
+import static org.junit.Assert.*;
+
public class JmxAttributeValidationExceptionTest {
private JmxAttribute jmxAttribute = new JmxAttribute("attr1");
- private JmxAttribute jmxAttribute2 = new JmxAttribute("attr2");
- @Before
- public void setUp() throws Exception {
+ @Test
+ public void testJmxAttributeValidationExceptionElement() throws Exception {
+ JmxAttribute attributeName = new JmxAttribute("attr_name");
+ JmxAttributeValidationException e = new JmxAttributeValidationException(attributeName);
+ assertThat(e.getAttributeNames(), CoreMatchers.hasItem(attributeName));
+ }
+ @Test
+ public void testJmxAttributeValidationExceptionList() throws Exception {
+ List attributeNames = new ArrayList<JmxAttribute>();
+ attributeNames.add(new JmxAttribute("att1"));
+ attributeNames.add(new JmxAttribute("att2"));
+ attributeNames.add(new JmxAttribute("att3"));
+ JmxAttributeValidationException e = new JmxAttributeValidationException(attributeNames);
+ assertEquals(e.getAttributeNames(), attributeNames);
}
@Test
- public void testGetAttributeNames() throws Exception {
+ public void testJmxAttributeValidationExceptionList2() throws Exception {
+ List attributeNames = new ArrayList<JmxAttribute>();
+ attributeNames.add(new JmxAttribute("att1"));
+ attributeNames.add(new JmxAttribute("att2"));
+ attributeNames.add(new JmxAttribute("att3"));
+ JmxAttributeValidationException e = new JmxAttributeValidationException("exception str",
+ new AccessDeniedException(""), attributeNames);
+ assertEquals(e.getAttributeNames(), attributeNames);
+ }
+ @Test
+ public void testJmxAttributeValidationExceptionJmxElement() throws Exception {
+ JmxAttribute attributeName = new JmxAttribute("attr_name");
+ JmxAttributeValidationException e = new JmxAttributeValidationException("exception str",
+ new AccessDeniedException(""), attributeName);
+ assertEquals(e.getAttributeNames(), Arrays.asList(attributeName));
}
@Test
public void testCheckNotNull() throws Exception {
try {
- JmxAttributeValidationException.checkNotNull(false, "message", jmxAttribute);
+ JmxAttributeValidationException.checkNotNull(false, jmxAttribute);
} catch (JmxAttributeValidationException e) {
assertJmxEx(e, jmxAttribute.getAttributeName() + " " + "message", jmxAttribute);
}
}
@Test
- public void testWrap() throws Exception {
+ public void testCheckCondition() throws Exception {
+ JmxAttributeValidationException.checkCondition(true, "message", jmxAttribute);
+ }
+ @Test(expected = JmxAttributeValidationException.class)
+ public void testJmxAttributeValidationException() throws Exception {
+ JmxAttributeValidationException.wrap(new Exception("tmp"), jmxAttribute);
}
- @Test
- public void testCheckCondition() throws Exception {
- try {
- JmxAttributeValidationException.checkCondition(false, "message", jmxAttribute);
- } catch (JmxAttributeValidationException e) {
- assertJmxEx(e, jmxAttribute.getAttributeName() + " " + "message", jmxAttribute);
- }
+ @Test(expected = JmxAttributeValidationException.class)
+ public void testJmxAttributeValidationException2() throws Exception {
+ JmxAttributeValidationException.wrap(new Exception("tmp"), "message", jmxAttribute);
+ }
+
+ @Test(expected = JmxAttributeValidationException.class)
+ public void testCheckConditionFalse() throws Exception {
+ JmxAttributeValidationException.checkCondition(false, "message", jmxAttribute);
}
private void assertJmxEx(JmxAttributeValidationException e, String message, JmxAttribute... attrNames) {
--- /dev/null
+package org.opendaylight.controller.config.api;
+
+import junit.framework.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+
+public class ModuleIdentifierTest {
+ String fact = new String("factory");
+ String inst = new String("instance");
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testConstructor() throws Exception {
+ ModuleIdentifier m = new ModuleIdentifier(null, "instance");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testConstructor2() throws Exception {
+ ModuleIdentifier m = new ModuleIdentifier("name", null);
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+
+ ModuleIdentifier m1 = new ModuleIdentifier(fact, inst);
+ assertEquals(m1, new ModuleIdentifier(fact, inst));
+ }
+
+ @Test
+ public void testEquals2() throws Exception {
+ assertNotEquals(new ModuleIdentifier(fact, inst), null);
+ }
+
+ @Test
+ public void testEquals3() throws Exception {
+ assertNotEquals(new ModuleIdentifier(fact, inst), new ModuleIdentifier(fact, "i"));
+ }
+
+ @Test
+ public void testEquals4() throws Exception {
+ assertNotEquals(new ModuleIdentifier(fact, inst), new ModuleIdentifier("f", inst));
+ }
+
+ @Test
+ public void testEquals5() throws Exception {
+ ModuleIdentifier m1 = new ModuleIdentifier(fact, inst);
+ assertEquals(m1, m1);
+ }
+
+ @Test
+ public void testHashCode() throws Exception {
+ int hash = new ModuleIdentifier(fact, inst).hashCode();
+ assertEquals(hash, new ModuleIdentifier("factory", "instance").hashCode());
+ }
+
+ @Test
+ public void testToString() throws Exception {
+ assertEquals( new ModuleIdentifier("factory", "instance").toString(),
+ new ModuleIdentifier("factory", "instance").toString());
+ }
+}
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;
import com.google.common.collect.Lists;
import java.util.Map;
+
+import org.junit.Assert;
import org.junit.Test;
public class ValidationExceptionTest {
}
fail("Duplicate exception should have failed");
}
+
+ @Test
+ public void testGetTrace() throws Exception {
+ ValidationException.ExceptionMessageWithStackTrace exp = new ValidationException.ExceptionMessageWithStackTrace();
+ exp.setTrace("trace");
+ Assert.assertEquals(exp.getTrace(), "trace");
+ }
+
+ @Test
+ public void testSetMessage() throws Exception {
+ ValidationException.ExceptionMessageWithStackTrace exp = new ValidationException.ExceptionMessageWithStackTrace();
+ exp.setMessage("message");
+ Assert.assertEquals(exp.getMessage(), "message");
+ }
+
+ @Test
+ public void testHashCode() throws Exception {
+ ValidationException.ExceptionMessageWithStackTrace exp = new ValidationException.ExceptionMessageWithStackTrace();
+ Assert.assertEquals(exp.hashCode(), new ValidationException.ExceptionMessageWithStackTrace().hashCode());
+ }
+
+ @Test
+ public void testExceptionMessageWithStackTraceConstructor() throws Exception {
+ ValidationException.ExceptionMessageWithStackTrace exp =
+ new ValidationException.ExceptionMessageWithStackTrace("string1", "string2");
+ Assert.assertEquals(exp, exp);
+ }
+
+ @Test
+ public void testExceptionMessageWithStackTraceConstructor2() throws Exception {
+ ValidationException.ExceptionMessageWithStackTrace exp =
+ new ValidationException.ExceptionMessageWithStackTrace("string1", "string2");
+ Assert.assertNotEquals(exp, null);
+ }
+
+ @Test
+ public void testExceptionMessageWithStackTraceConstructor3() throws Exception {
+ ValidationException.ExceptionMessageWithStackTrace exp =
+ new ValidationException.ExceptionMessageWithStackTrace("string1", "string2");
+ Assert.assertNotEquals(exp, new Exception());
+ }
+
+ @Test
+ public void testExceptionMessageWithStackTraceConstructor4() throws Exception {
+ ValidationException.ExceptionMessageWithStackTrace exp =
+ new ValidationException.ExceptionMessageWithStackTrace("string1", "string2");
+ Assert.assertEquals(exp, new ValidationException.ExceptionMessageWithStackTrace("string1", "string2"));
+ }
+
+ @Test
+ public void testEqual() throws Exception {
+ ValidationException.ExceptionMessageWithStackTrace exp =
+ new ValidationException.ExceptionMessageWithStackTrace("string1", "string2");
+ ValidationException.ExceptionMessageWithStackTrace exp2 =
+ new ValidationException.ExceptionMessageWithStackTrace(null, "string2");
+ Assert.assertNotEquals(exp, exp2);
+ }
+
+ @Test
+ public void testEqual2() throws Exception {
+ ValidationException.ExceptionMessageWithStackTrace exp =
+ new ValidationException.ExceptionMessageWithStackTrace("string1", "string2");
+ ValidationException.ExceptionMessageWithStackTrace exp2 =
+ new ValidationException.ExceptionMessageWithStackTrace("different", "string2");
+ Assert.assertNotEquals(exp, exp2);
+ }
+
+
+ @Test
+ public void testEqual3() throws Exception {
+ ValidationException.ExceptionMessageWithStackTrace exp =
+ new ValidationException.ExceptionMessageWithStackTrace("string1", "string2");
+ ValidationException.ExceptionMessageWithStackTrace exp2 =
+ new ValidationException.ExceptionMessageWithStackTrace("string1", null);
+ Assert.assertNotEquals(exp, exp2);
+ }
+
+ @Test
+ public void testEqual4() throws Exception {
+ ValidationException.ExceptionMessageWithStackTrace exp =
+ new ValidationException.ExceptionMessageWithStackTrace("string1", "string2");
+ ValidationException.ExceptionMessageWithStackTrace exp2 =
+ new ValidationException.ExceptionMessageWithStackTrace("string1", "different");
+ Assert.assertNotEquals(exp, exp2);
+ }
+
+ @Test
+ public void testEqual5() throws Exception {
+ ValidationException.ExceptionMessageWithStackTrace exp =
+ new ValidationException.ExceptionMessageWithStackTrace(null, "string2");
+ ValidationException.ExceptionMessageWithStackTrace exp2 =
+ new ValidationException.ExceptionMessageWithStackTrace("string1", "string2");
+ Assert.assertNotEquals(exp, exp2);
+ }
+
+ @Test
+ public void testEqual6() throws Exception {
+ ValidationException.ExceptionMessageWithStackTrace exp =
+ new ValidationException.ExceptionMessageWithStackTrace("string1", null);
+ ValidationException.ExceptionMessageWithStackTrace exp2 =
+ new ValidationException.ExceptionMessageWithStackTrace("string1", "string2");
+ Assert.assertNotEquals(exp, exp2);
+ }
}
\ No newline at end of file
--- /dev/null
+package org.opendaylight.controller.config.api.jmx;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.management.ObjectName;
+import java.util.ArrayList;
+import java.util.List;
+
+public class CommitStatusTest {
+ List newInst = new ArrayList<ObjectName>();
+ List reusedInst = new ArrayList<ObjectName>();
+ List recreatedInst = new ArrayList<ObjectName>();
+
+ @Before
+ public void setUp() throws Exception {
+ newInst.add(new ObjectName("domain: key1 = value1 , key2 = value2"));
+ reusedInst.add(new ObjectName("o2: key = val"));
+ recreatedInst.add(new ObjectName("o3: key = k"));
+ }
+ @Test
+ public void testCommitStatus() throws Exception {
+ CommitStatus status = new CommitStatus(newInst, reusedInst, recreatedInst);
+ Assert.assertEquals(status.getNewInstances(), newInst);
+ Assert.assertEquals(status.getRecreatedInstances(), recreatedInst);
+ Assert.assertEquals(status.getReusedInstances(), reusedInst);
+ }
+
+ @Test
+ public void testEqual() throws Exception {
+ CommitStatus status = new CommitStatus(newInst, reusedInst, recreatedInst);
+ Assert.assertEquals(status, new CommitStatus(newInst, reusedInst, recreatedInst));
+ Assert.assertEquals(status.toString(), new CommitStatus(newInst, reusedInst, recreatedInst).toString());
+ Assert.assertEquals(status, status);
+ }
+
+ @Test
+ public void testHashCode() throws Exception {
+ CommitStatus status = new CommitStatus(newInst, reusedInst, recreatedInst);
+ Assert.assertEquals(status.hashCode(), new CommitStatus(newInst, reusedInst, recreatedInst).hashCode());
+ }
+
+ @Test
+ public void testNotEqual() throws Exception {
+ List newInst2 = new ArrayList<ObjectName>();
+ List reusedInst2 = new ArrayList<ObjectName>();
+ List recreatedInst2 = new ArrayList<ObjectName>();
+
+ newInst2.add(new ObjectName("first: key1 = value1"));
+ reusedInst2.add(new ObjectName("second: key = val"));
+ recreatedInst2.add(new ObjectName("third: key = k"));
+
+ CommitStatus status = new CommitStatus(newInst, reusedInst, recreatedInst);
+ Assert.assertNotEquals(status, null);
+ Assert.assertNotEquals(status, new Object());
+ Assert.assertNotEquals(status, new CommitStatus(newInst2, reusedInst, recreatedInst));
+ Assert.assertNotEquals(status, new CommitStatus(newInst, reusedInst2, recreatedInst));
+ Assert.assertNotEquals(status, new CommitStatus(newInst, reusedInst, recreatedInst2));
+
+ CommitStatus status2 = new CommitStatus(newInst, reusedInst, recreatedInst);
+ }
+}
--- /dev/null
+package org.opendaylight.controller.config.api.jmx;
+
+
+import org.junit.Test;
+import org.opendaylight.controller.config.api.jmx.constants.ConfigRegistryConstants;
+
+public class ConfigRegistryConstantsTest {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCreateON() throws Exception {
+ ConfigRegistryConstants.createON("test.<:", "asd", "asd");
+ }
+}
import com.google.common.base.Throwables;
import com.google.common.collect.Maps;
+
+import java.util.HashMap;
import java.util.Map;
import javax.management.ObjectName;
import junit.framework.Assert;
fail(test + " should have failed on " + ex);
}
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCreateON() throws Exception {
+ ObjectNameUtil.createON(">}+!#");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCreateON2() throws Exception {
+ Map<String, String> map = new HashMap<>();
+ ObjectNameUtil.createON(">}+!#", map);
+ }
}