From 0578156b721fa01c8c645b8f9625ecebdb6449e4 Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Wed, 27 Jul 2016 11:05:51 +0200 Subject: HONEYCOMB-130: Separate v3po plugin from HC infra Creating folders: - common/ - infra/ - v3po/ - vpp-common/ Change-Id: I2c39e1b17e39e7c0f0628f44aa5fe08563fa06e4 Signed-off-by: Maros Marsalek --- v3po/translate-impl/Readme.adoc | 9 -- v3po/translate-impl/pom.xml | 88 ---------------- .../translate/impl/read/GenericListReader.java | 117 --------------------- .../v3po/translate/impl/read/GenericReader.java | 70 ------------ .../translate/impl/write/GenericListWriter.java | 106 ------------------- .../v3po/translate/impl/write/GenericWriter.java | 61 ----------- .../impl/write/GenericListWriterTest.java | 83 --------------- .../translate/impl/write/GenericWriterTest.java | 64 ----------- 8 files changed, 598 deletions(-) delete mode 100644 v3po/translate-impl/Readme.adoc delete mode 100644 v3po/translate-impl/pom.xml delete mode 100644 v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/GenericListReader.java delete mode 100644 v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/GenericReader.java delete mode 100644 v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/GenericListWriter.java delete mode 100644 v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/GenericWriter.java delete mode 100644 v3po/translate-impl/src/test/java/io/fd/honeycomb/v3po/translate/impl/write/GenericListWriterTest.java delete mode 100644 v3po/translate-impl/src/test/java/io/fd/honeycomb/v3po/translate/impl/write/GenericWriterTest.java (limited to 'v3po/translate-impl') diff --git a/v3po/translate-impl/Readme.adoc b/v3po/translate-impl/Readme.adoc deleted file mode 100644 index 1e5c63604..000000000 --- a/v3po/translate-impl/Readme.adoc +++ /dev/null @@ -1,9 +0,0 @@ -= Honeycomb translation layer implementation - -Provides composite implementations of child, list and root readers/writers. - -Root readers/writers can be used to provide data translation at root node level. -List readers/writers help with data translation for nodes modeled as YANG lists. -Child readers/writers can be used to provide data translation for non-leaf nodes. - -Readers and writers can be easily extended using customizers defined in the translate-spi module. \ No newline at end of file diff --git a/v3po/translate-impl/pom.xml b/v3po/translate-impl/pom.xml deleted file mode 100644 index 214d48ff0..000000000 --- a/v3po/translate-impl/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - io.fd.honeycomb.common - api-parent - 1.0.0-SNAPSHOT - ../../common/api-parent - - - 4.0.0 - io.fd.honeycomb.v3po - translate-impl - 1.0.0-SNAPSHOT - bundle - - - - ${project.groupId} - translate-api - ${project.version} - - - ${project.groupId} - translate-spi - ${project.version} - - - ${project.groupId} - translate-utils - ${project.version} - - - - - ${project.groupId} - v3po-api - ${project.version} - test - - - junit - junit - test - - - org.mockito - mockito-all - test - - - - - - - maven-jar-plugin - - - org.apache.felix - maven-bundle-plugin - true - - - ${project.groupId}.${project.artifactId} - - io.fd.honeycomb.v3po.translate.impl.* - - - - - - - - diff --git a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/GenericListReader.java b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/GenericListReader.java deleted file mode 100644 index defb2e51b..000000000 --- a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/GenericListReader.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * 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. - */ - -package io.fd.honeycomb.v3po.translate.impl.read; - -import static com.google.common.base.Preconditions.checkArgument; - -import com.google.common.annotations.Beta; -import com.google.common.base.Optional; -import io.fd.honeycomb.v3po.translate.read.ListReader; -import io.fd.honeycomb.v3po.translate.read.ReadContext; -import io.fd.honeycomb.v3po.translate.read.ReadFailedException; -import io.fd.honeycomb.v3po.translate.spi.read.ListReaderCustomizer; -import io.fd.honeycomb.v3po.translate.util.RWUtils; -import io.fd.honeycomb.v3po.translate.util.read.AbstractGenericReader; -import java.util.ArrayList; -import java.util.List; -import javax.annotation.Nonnull; -import javax.annotation.concurrent.ThreadSafe; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.Identifiable; -import org.opendaylight.yangtools.yang.binding.Identifier; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Composite implementation of {@link ListReader} able to place the read result into parent builder object intended - * for list node type. - *

- * This reader checks if the IDs are wildcarded in which case it performs read of all list entries. In case the ID has a - * key, it reads only the specified value. - */ -@Beta -@ThreadSafe -public final class GenericListReader, K extends Identifier, B extends Builder> - extends AbstractGenericReader implements ListReader { - - private static final Logger LOG = LoggerFactory.getLogger(GenericListReader.class); - - private final ListReaderCustomizer customizer; - - /** - * Create new {@link GenericListReader} - * - * @param managedDataObjectType Class object for managed data type. Must come from a list node type. - * @param customizer Customizer instance to customize this generic reader - */ - public GenericListReader(@Nonnull final InstanceIdentifier managedDataObjectType, - @Nonnull final ListReaderCustomizer customizer) { - super(managedDataObjectType); - this.customizer = customizer; - } - - @Override - @Nonnull - public List readList(@Nonnull final InstanceIdentifier id, - @Nonnull final ReadContext ctx) throws ReadFailedException { - LOG.trace("{}: Reading all list entries", this); - final List allIds = getAllIds(id, ctx); - LOG.debug("{}: Reading list entries for: {}", this, allIds); - - final ArrayList allEntries = new ArrayList<>(allIds.size()); - for (K key : allIds) { - final InstanceIdentifier.IdentifiableItem currentBdItem = RWUtils.getCurrentIdItem(id, key); - final InstanceIdentifier keyedId = RWUtils.replaceLastInId(id, currentBdItem); - final Optional read = readCurrent(keyedId, ctx); - if (read.isPresent()) { - final DataObject singleItem = read.get(); - checkArgument(getManagedDataObjectType().getTargetType().isAssignableFrom(singleItem.getClass())); - allEntries.add(getManagedDataObjectType().getTargetType().cast(singleItem)); - } - } - return allEntries; - } - - @Override - public List getAllIds(@Nonnull final InstanceIdentifier id, @Nonnull final ReadContext ctx) - throws ReadFailedException { - LOG.trace("{}: Getting all list ids", this); - final List allIds = customizer.getAllIds(id, ctx); - LOG.debug("{}: All list ids: {}", this, allIds); - return allIds; - } - - @Override - public void merge(@Nonnull final Builder builder, @Nonnull final List readData) { - customizer.merge(builder, readData); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final B builder, - @Nonnull final ReadContext ctx) - throws ReadFailedException { - customizer.readCurrentAttributes(id, builder, ctx); - } - - @Override - public B getBuilder(@Nonnull final InstanceIdentifier id) { - return customizer.getBuilder(id); - } - -} diff --git a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/GenericReader.java b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/GenericReader.java deleted file mode 100644 index eace7fa89..000000000 --- a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/GenericReader.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * 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. - */ - -package io.fd.honeycomb.v3po.translate.impl.read; - -import com.google.common.annotations.Beta; -import io.fd.honeycomb.v3po.translate.read.ReadContext; -import io.fd.honeycomb.v3po.translate.read.ReadFailedException; -import io.fd.honeycomb.v3po.translate.read.Reader; -import io.fd.honeycomb.v3po.translate.spi.read.ReaderCustomizer; -import io.fd.honeycomb.v3po.translate.util.read.AbstractGenericReader; -import javax.annotation.Nonnull; -import javax.annotation.concurrent.ThreadSafe; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -/** - * Composite implementation of {@link Reader}. - */ -@Beta -@ThreadSafe -public final class GenericReader> extends AbstractGenericReader - implements Reader { - - private final ReaderCustomizer customizer; - - /** - * Create a new {@link GenericReader}. - * - * @param id Instance identifier for managed data type - * @param customizer Customizer instance to customize this generic reader - */ - public GenericReader(@Nonnull final InstanceIdentifier id, - @Nonnull final ReaderCustomizer customizer) { - super(id); - this.customizer = customizer; - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final B builder, - @Nonnull final ReadContext ctx) throws ReadFailedException { - customizer.readCurrentAttributes(id, builder, ctx); - } - - @Override - public B getBuilder(@Nonnull final InstanceIdentifier id) { - return customizer.getBuilder(id); - } - - @Override - public void merge(@Nonnull final Builder parentBuilder, @Nonnull final C readValue) { - customizer.merge(parentBuilder, readValue); - } - -} diff --git a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/GenericListWriter.java b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/GenericListWriter.java deleted file mode 100644 index 32daf5975..000000000 --- a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/GenericListWriter.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * 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. - */ - -package io.fd.honeycomb.v3po.translate.impl.write; - -import io.fd.honeycomb.v3po.translate.spi.write.ListWriterCustomizer; -import io.fd.honeycomb.v3po.translate.spi.write.WriterCustomizer; -import io.fd.honeycomb.v3po.translate.util.RWUtils; -import io.fd.honeycomb.v3po.translate.util.write.AbstractGenericWriter; -import io.fd.honeycomb.v3po.translate.write.ListWriter; -import io.fd.honeycomb.v3po.translate.write.WriteContext; -import io.fd.honeycomb.v3po.translate.write.WriteFailedException; -import javax.annotation.Nonnull; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.Identifiable; -import org.opendaylight.yangtools.yang.binding.Identifier; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -/** - * Generic list node writer with customizable behavior thanks to injected customizer. - */ -public final class GenericListWriter, K extends Identifier> extends - AbstractGenericWriter implements ListWriter { - - private final WriterCustomizer customizer; - - public GenericListWriter(@Nonnull final InstanceIdentifier type, - @Nonnull final ListWriterCustomizer customizer) { - super(type); - this.customizer = customizer; - } - - @Override - protected void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final D data, - @Nonnull final WriteContext ctx) throws WriteFailedException { - customizer.writeCurrentAttributes(id, data, ctx); - } - - @Override - protected void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final D dataBefore, - @Nonnull final WriteContext ctx) throws WriteFailedException { - customizer.deleteCurrentAttributes(id, dataBefore, ctx); - } - - @Override - protected void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final D dataBefore, - @Nonnull final D dataAfter, @Nonnull final WriteContext ctx) - throws WriteFailedException { - customizer.updateCurrentAttributes(id, dataBefore, dataAfter, ctx); - } - - @Override - protected void writeCurrent(final InstanceIdentifier id, final D data, final WriteContext ctx) - throws WriteFailedException { - // Make sure the key is present - if (isWildcarded(id)) { - super.writeCurrent(getSpecificId(id, data), data, ctx); - } else { - super.writeCurrent(id, data, ctx); - } - } - - @Override - protected void updateCurrent(final InstanceIdentifier id, final D dataBefore, final D dataAfter, - final WriteContext ctx) throws WriteFailedException { - // Make sure the key is present - if (isWildcarded(id)) { - super.updateCurrent(getSpecificId(id, dataBefore), dataBefore, dataAfter, ctx); - } else { - super.updateCurrent(id, dataBefore, dataAfter, ctx); - } - } - - @Override - protected void deleteCurrent(final InstanceIdentifier id, final D dataBefore, final WriteContext ctx) - throws WriteFailedException { - // Make sure the key is present - if (isWildcarded(id)) { - super.deleteCurrent(getSpecificId(id, dataBefore), dataBefore, ctx); - } else { - super.deleteCurrent(id, dataBefore, ctx); - } - } - - private boolean isWildcarded(final InstanceIdentifier id) { - return id.firstIdentifierOf(getManagedDataObjectType().getTargetType()).isWildcarded(); - } - - private InstanceIdentifier getSpecificId(final InstanceIdentifier currentId, final D current) { - return RWUtils.replaceLastInId(currentId, - new InstanceIdentifier.IdentifiableItem<>(currentId.getTargetType(), current.getKey())); - } -} diff --git a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/GenericWriter.java b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/GenericWriter.java deleted file mode 100644 index 65c192ffa..000000000 --- a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/GenericWriter.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * 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. - */ - -package io.fd.honeycomb.v3po.translate.impl.write; - -import io.fd.honeycomb.v3po.translate.spi.write.WriterCustomizer; -import io.fd.honeycomb.v3po.translate.util.write.AbstractGenericWriter; -import io.fd.honeycomb.v3po.translate.write.WriteContext; -import io.fd.honeycomb.v3po.translate.write.WriteFailedException; -import javax.annotation.Nonnull; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -/** - * Generic writer with customizable behavior thanks to injected customizer. - */ -public final class GenericWriter extends AbstractGenericWriter { - - private final WriterCustomizer customizer; - - public GenericWriter(@Nonnull final InstanceIdentifier type, - @Nonnull final WriterCustomizer customizer) { - super(type); - this.customizer = customizer; - } - - @Override - protected void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final D data, - @Nonnull final WriteContext ctx) throws WriteFailedException { - // TODO wrap all customizer invocations in try catch, and wrap runtime exceptions in ReadFailed - // TODO same for readers - customizer.writeCurrentAttributes(id, data, ctx); - } - - @Override - protected void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final D dataBefore, - @Nonnull final WriteContext ctx) throws WriteFailedException { - customizer.deleteCurrentAttributes(id, dataBefore, ctx); - } - - @Override - protected void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final D dataBefore, - @Nonnull final D dataAfter, - @Nonnull final WriteContext ctx) throws WriteFailedException { - customizer.updateCurrentAttributes(id, dataBefore, dataAfter, ctx); - } -} diff --git a/v3po/translate-impl/src/test/java/io/fd/honeycomb/v3po/translate/impl/write/GenericListWriterTest.java b/v3po/translate-impl/src/test/java/io/fd/honeycomb/v3po/translate/impl/write/GenericListWriterTest.java deleted file mode 100644 index 54a7466e1..000000000 --- a/v3po/translate-impl/src/test/java/io/fd/honeycomb/v3po/translate/impl/write/GenericListWriterTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * 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. - */ - -package io.fd.honeycomb.v3po.translate.impl.write; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.honeycomb.v3po.translate.spi.write.ListWriterCustomizer; -import io.fd.honeycomb.v3po.translate.write.WriteContext; -import java.util.Collections; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.Identifiable; -import org.opendaylight.yangtools.yang.binding.Identifier; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class GenericListWriterTest { - - private static final InstanceIdentifier - DATA_OBJECT_INSTANCE_IDENTIFIER = InstanceIdentifier.create(IdentifiableDataObject.class); - @Mock - private ListWriterCustomizer customizer; - @Mock - private WriteContext ctx; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testUpdate() throws Exception { - final GenericListWriter writer = - new GenericListWriter<>(DATA_OBJECT_INSTANCE_IDENTIFIER, customizer); - - final IdentifiableDataObject before = mock(IdentifiableDataObject.class); - final DataObjectIdentifier beforeKey = mock(DataObjectIdentifier.class); - when(before.getKey()).thenReturn(beforeKey); - final IdentifiableDataObject after = mock(IdentifiableDataObject.class); - final DataObjectIdentifier keyAfter = mock(DataObjectIdentifier.class); - when(after.getKey()).thenReturn(keyAfter); - - assertEquals(DATA_OBJECT_INSTANCE_IDENTIFIER, writer.getManagedDataObjectType()); - - final InstanceIdentifier keyedIdBefore = - (InstanceIdentifier) InstanceIdentifier.create(Collections - .singleton(new InstanceIdentifier.IdentifiableItem<>(IdentifiableDataObject.class, beforeKey))); - final InstanceIdentifier keyedIdAfter = - (InstanceIdentifier) InstanceIdentifier.create(Collections - .singleton(new InstanceIdentifier.IdentifiableItem<>(IdentifiableDataObject.class, keyAfter))); - - writer.update(DATA_OBJECT_INSTANCE_IDENTIFIER, before, after, ctx); - verify(customizer).updateCurrentAttributes(keyedIdBefore, before, after, ctx); - - writer.update(DATA_OBJECT_INSTANCE_IDENTIFIER, before, null, ctx); - verify(customizer).deleteCurrentAttributes(keyedIdBefore, before, ctx); - - writer.update(DATA_OBJECT_INSTANCE_IDENTIFIER, null, after, ctx); - verify(customizer).writeCurrentAttributes(keyedIdAfter, after, ctx); - } - - private abstract static class IdentifiableDataObject implements DataObject, Identifiable {} - private abstract static class DataObjectIdentifier implements Identifier {} -} \ No newline at end of file diff --git a/v3po/translate-impl/src/test/java/io/fd/honeycomb/v3po/translate/impl/write/GenericWriterTest.java b/v3po/translate-impl/src/test/java/io/fd/honeycomb/v3po/translate/impl/write/GenericWriterTest.java deleted file mode 100644 index 87f18965b..000000000 --- a/v3po/translate-impl/src/test/java/io/fd/honeycomb/v3po/translate/impl/write/GenericWriterTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * 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. - */ - -package io.fd.honeycomb.v3po.translate.impl.write; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import io.fd.honeycomb.v3po.translate.spi.write.WriterCustomizer; -import io.fd.honeycomb.v3po.translate.write.WriteContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class GenericWriterTest { - - private static final InstanceIdentifier - DATA_OBJECT_INSTANCE_IDENTIFIER = InstanceIdentifier.create(DataObject.class); - @Mock - private WriterCustomizer customizer; - @Mock - private WriteContext ctx; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testUpdate() throws Exception { - final GenericWriter writer = - new GenericWriter<>(DATA_OBJECT_INSTANCE_IDENTIFIER, customizer); - - final DataObject before = mock(DataObject.class); - final DataObject after = mock(DataObject.class); - - assertEquals(DATA_OBJECT_INSTANCE_IDENTIFIER, writer.getManagedDataObjectType()); - writer.update(DATA_OBJECT_INSTANCE_IDENTIFIER, before, after, ctx); - verify(customizer).updateCurrentAttributes(DATA_OBJECT_INSTANCE_IDENTIFIER, before, after, ctx); - - writer.update(DATA_OBJECT_INSTANCE_IDENTIFIER, before, null, ctx); - verify(customizer).deleteCurrentAttributes(DATA_OBJECT_INSTANCE_IDENTIFIER, before, ctx); - - writer.update(DATA_OBJECT_INSTANCE_IDENTIFIER, null, after, ctx); - verify(customizer).writeCurrentAttributes(DATA_OBJECT_INSTANCE_IDENTIFIER, after, ctx); - } -} \ No newline at end of file -- cgit 1.2.3-korg