<groupId>org.opendaylight.mdsal</groupId>
<artifactId>mdsal-common-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>general-entity</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>concepts</artifactId>
package org.opendaylight.mdsal.binding.api.clustering;
import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
import javax.annotation.Nonnull;
import org.opendaylight.mdsal.common.api.clustering.GenericEntity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.core.general.entity.rev150930.EntityKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
* @param type the type of the entity
* @param entityName the name of the entity used to construct a general-entity InstanceIdentifier
*/
- // FIXME: needs to be enabled in a follow-up
-// public Entity(@Nonnull String type, @Nonnull String entityName) {
-// super(type, InstanceIdentifier.builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.
-// ns.yang.controller.md.sal.core.general.entity.rev150820.Entity.class,
-// new EntityKey(Preconditions.checkNotNull(entityName, "entityName should not be null"))).build());
-// }
+ public Entity(@Nonnull String type, @Nonnull String entityName) {
+ super(type, InstanceIdentifier.builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.
+ mdsal.core.general.entity.rev150930.Entity.class,
+ new EntityKey(Preconditions.checkNotNull(entityName, "entityName should not be null"))).build());
+ }
}
package org.opendaylight.mdsal.binding.api.clustering;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotEquals;
import org.apache.commons.lang3.SerializationUtils;
import org.junit.Test;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.Identifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
assertNotEquals("hashCode", entity1.hashCode(), new Entity(ENTITY_TYPE2, ID2).hashCode());
}
- static class TestDataObject1 implements DataObject {
- @Override
- public Class<? extends DataContainer> getImplementedInterface() {
- return null;
- }
- }
-
@Test
public void testEquals() {
Entity entity1 = new Entity(ENTITY_TYPE1, ID1);
assertEquals("Same", true, entity1.equals(entity1));
assertEquals("Same", true, entity1.equals(new Entity(ENTITY_TYPE1, ID1)));
assertEquals("Different entity type", false, entity1.equals(new Entity(ENTITY_TYPE2, ID1)));
- assertEquals("Different yang ID", false, entity1.equals(new Entity(ENTITY_TYPE1, ID2)));
+ assertEquals("Different entity ID", false, entity1.equals(new Entity(ENTITY_TYPE1, ID2)));
assertEquals("Different Object", false, entity1.equals(new Object()));
assertEquals("Equals null", false, entity1.equals(null));
}
assertEquals("getId", entity.getIdentifier(), clone.getIdentifier());
}
+ @Test
+ public void testEntityNameConstructor() {
+ Entity entity = new Entity(ENTITY_TYPE1, "foo");
+
+ Identifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.
+ mdsal.core.general.entity.rev150930.Entity> keyID = entity.getIdentifier().firstKeyOf(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.core.general.entity.rev150930.Entity.class);
+ assertNotNull("List key not found", keyID);
+ }
+
+ static class TestDataObject1 implements DataObject {
+ @Override
+ public Class<? extends DataContainer> getImplementedInterface() {
+ return null;
+ }
+ }
+
static class TestDataObject2 implements DataObject {
@Override
public Class<? extends DataContainer> getImplementedInterface() {
<artifactId>yang-ext</artifactId>
<version>2013.09.07.8-SNAPSHOT</version>
</dependency>
-
+ <dependency>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>general-entity</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </dependency>
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
<artifactId>mdsal-binding-test-model</artifactId>
<groupId>${project.groupId}.model</groupId>
<artifactId>yang-ext</artifactId>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}.model</groupId>
+ <artifactId>general-entity</artifactId>
+ </dependency>
</dependencies>
</project>
<feature name='odl-mdsal-binding-api' version='${project.version}' description='OpenDaylight :: MD-SAL :: Binding Base Concepts'>
<feature version='${project.version}'>odl-mdsal-common</feature>
<feature version='${project.version}'>odl-mdsal-binding-base</feature>
+ <bundle>mvn:org.opendaylight.mdsal.model/general-entity/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.mdsal/mdsal-binding-api/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.mdsal/mdsal-binding-util/{{VERSION}}</bundle>
</feature>
<properties>
<yangtools.version>0.8.0-SNAPSHOT</yangtools.version>
+ <salGeneratorPath>target/generated-sources/sal</salGeneratorPath>
<!-- FIXME: these will be upstreamed -->
<maven.depends.version>1.2</maven.depends.version>
org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl
</codeGeneratorClass>
<outputBaseDir>
- target/generated-sources/sal
+ ${salGeneratorPath}
</outputBaseDir>
</generator>
<generator>
<codeGeneratorClass>org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
- <outputBaseDir>target/site/restconf</outputBaseDir>
+ <outputBaseDir>target/site/models</outputBaseDir>
</generator>
<generator>
<codeGeneratorClass>org.opendaylight.yangtools.yang.wadl.generator.maven.WadlGenerator</codeGeneratorClass>
- <outputBaseDir>target/site/restconf</outputBaseDir>
+ <outputBaseDir>target/site/models</outputBaseDir>
</generator>
</codeGenerators>
<inspectDependencies>true</inspectDependencies>
<configuration>
<sources>
<source>target/generated-sources/parser</source>
- <source>target/generated-sources/sal</source>
+ <source>${salGeneratorPath}</source>
<source>${basedir}/src/main/xtend-gen</source>
</sources>
</configuration>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ </plugin>
</plugins>
</build>
</project>
package org.opendaylight.mdsal.dom.api.clustering;
import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
import javax.annotation.Nonnull;
import org.opendaylight.mdsal.common.api.clustering.GenericEntity;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
/**
public class DOMEntity extends GenericEntity<YangInstanceIdentifier> {
private static final long serialVersionUID = 1L;
- // FIXME: needs update once the model is in
-// private static final QName ENTITY_QNAME =
-// org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.core.general.entity.rev150820.Entity.QNAME;
-// private static final QName ENTITY_NAME = QName.create(ENTITY_QNAME, "name");
+ static final QName ENTITY = QName.create(
+ "urn:opendaylight:params:xml:ns:yang:mdsal:core:general-entity", "2015-09-30", "entity").intern();
+ static final QName ENTITY_NAME = QName.create(ENTITY, "name").intern();
/** Constructs an instance.
* @param type the type of the entity
* @param entityName the name of the entity used to construct a general-entity YangInstanceIdentifier
*/
- // FIXME: needs update once the model is in
-// public DOMEntity(@Nonnull String type, @Nonnull String entityName) {
-// super(type, YangInstanceIdentifier.builder().node(ENTITY_QNAME).nodeWithKey(ENTITY_QNAME, ENTITY_NAME,
-// Preconditions.checkNotNull(entityName, "entityName should not be null")).build());
-// }
+ public DOMEntity(@Nonnull String type, @Nonnull String entityName) {
+ super(type, YangInstanceIdentifier.builder().node(ENTITY).nodeWithKey(ENTITY, ENTITY_NAME,
+ Preconditions.checkNotNull(entityName, "entityName should not be null")).build());
+ }
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.dom.api.clustering;
+
+import static org.opendaylight.mdsal.dom.api.clustering.DOMEntity.ENTITY;
+import static org.junit.Assert.*;
+import java.util.List;
+import java.util.Map.Entry;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+
+/**
+ * @author Thomas Pantelis
+ */
+public class DOMEntityTest {
+ static String ENTITY_TYPE1 = "type1";
+ static String ENTITY_TYPE2 = "type2";
+ static final YangInstanceIdentifier ID1 = YangInstanceIdentifier.of(QName.create("test", "2015-11-24", "one"));
+ static final YangInstanceIdentifier ID2 = YangInstanceIdentifier.of(QName.create("test", "2015-11-24", "two"));
+
+ @Test
+ public void testHashCode() {
+ DOMEntity entity1 = new DOMEntity(ENTITY_TYPE1, ID1);
+
+ assertEquals("hashCode", entity1.hashCode(), new DOMEntity(ENTITY_TYPE1, ID1).hashCode());
+ assertNotEquals("hashCode", entity1.hashCode(), new DOMEntity(ENTITY_TYPE2, ID2).hashCode());
+ }
+
+ @Test
+ public void testEquals() {
+ DOMEntity entity1 = new DOMEntity(ENTITY_TYPE1, ID1);
+
+ assertEquals("Same", true, entity1.equals(entity1));
+ assertEquals("Same", true, entity1.equals(new DOMEntity(ENTITY_TYPE1, ID1)));
+ assertEquals("Different entity type", false, entity1.equals(new DOMEntity(ENTITY_TYPE2, ID1)));
+ assertEquals("Different entity ID", false, entity1.equals(new DOMEntity(ENTITY_TYPE1, ID2)));
+ assertEquals("Different Object", false, entity1.equals(new Object()));
+ assertEquals("Equals null", false, entity1.equals(null));
+ }
+
+ @Test
+ public void testEntityNameConstructor() {
+ DOMEntity entity = new DOMEntity(ENTITY_TYPE1, "foo");
+
+ List<PathArgument> pathArgs = entity.getIdentifier().getPathArguments();
+ assertEquals("pathArgs size", 2, pathArgs.size());
+ assertEquals("First PathArgument node type", ENTITY, pathArgs.get(0).getNodeType());
+ assertEquals("Second PathArgument node type", ENTITY, pathArgs.get(1).getNodeType());
+ Entry<QName, Object> key = ((NodeIdentifierWithPredicates) pathArgs.get(1)).getKeyValues().entrySet().iterator().next();
+ assertEquals("Key node type", QName.create(ENTITY, "name"), key.getKey());
+ assertEquals("Key value", "foo", key.getValue());
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+ Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <artifactId>model-parent</artifactId>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <version>0.8.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>general-entity</artifactId>
+ <name>${project.artifactId}</name>
+ <description>${project.artifactId}</description>
+ <packaging>bundle</packaging>
+
+</project>
--- /dev/null
+module odl-general-entity {
+ namespace "urn:opendaylight:params:xml:ns:yang:mdsal:core:general-entity";
+ prefix "odl-general-entity";
+
+ description "Defines a model to describe a general entity whose path can be used as an ID for an entity that isn't otherwise modelled";
+
+ revision 2015-09-30 {
+ description "Initial revision";
+ }
+
+ list entity {
+ key name;
+ leaf name {
+ type string;
+ }
+ }
+}
\ No newline at end of file
<module>iana</module>
<module>ietf</module>
<module>l2-types</module>
+ <module>general-entity</module>
</modules>
<dependencyManagement>