<commit_before>/*
 * 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.controller.cluster.datastore.messages;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import akka.actor.ExtendedActorSystem;
import akka.testkit.JavaTestKit;
import java.io.NotSerializableException;
import java.util.List;
import org.junit.Test;
import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
import org.opendaylight.controller.cluster.datastore.AbstractTest;
import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
import org.opendaylight.controller.cluster.datastore.modification.MergeModification;
import org.opendaylight.controller.cluster.datastore.modification.Modification;
import org.opendaylight.controller.cluster.datastore.modification.WriteModification;
import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;

/**
 * Unit tests for ReadyLocalTransactionSerializer.
 *
 * @author <NAME>
 */
public class ReadyLocalTransactionSerializerTest extends AbstractTest {

    @Test
    public void testToAndFromBinary() throws NotSerializableException {
        DataTree dataTree = new InMemoryDataTreeFactory().create(
            DataTreeConfiguration.DEFAULT_OPERATIONAL, TestModel.createTestContext());
        DataTreeModification modification = dataTree.takeSnapshot().newModification();

        ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
        new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
        MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
        new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);

        TransactionIdentifier txId = nextTransactionId();
        ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);

        final ExtendedActorSystem system = (ExtendedActorSystem) ExtendedActorSystem.create("test");
        final Object deserialized;
        try {
            final ReadyLocalTransactionSerializer serializer = new ReadyLocalTransactionSerializer(system);
            final byte[] bytes = serializer.toBinary(readyMessage);
            deserialized = serializer.fromBinary(bytes, ReadyLocalTransaction.class);
        } finally {
            JavaTestKit.shutdownActorSystem(system);
        }

        assertNotNull("fromBinary returned null", deserialized);
        assertEquals("fromBinary return type", BatchedModifications.class, deserialized.getClass());
        BatchedModifications batched = (BatchedModifications)deserialized;
        assertEquals("getTransactionID", txId, batched.getTransactionId());
        assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, batched.getVersion());

        List<Modification> batchedMods = batched.getModifications();
        assertEquals("getModifications size", 2, batchedMods.size());

        Modification mod = batchedMods.get(0);
        assertEquals("Modification type", WriteModification.class, mod.getClass());
        assertEquals("Modification getPath", TestModel.TEST_PATH, ((WriteModification)mod).getPath());
        assertEquals("Modification getData", writeData, ((WriteModification)mod).getData());

        mod = batchedMods.get(1);
        assertEquals("Modification type", MergeModification.class, mod.getClass());
        assertEquals("Modification getPath", TestModel.OUTER_LIST_PATH, ((MergeModification)mod).getPath());
        assertEquals("Modification getData", mergeData, ((MergeModification)mod).getData());
    }
}
<commit_msg>Migrate test to use javadsl.TestKit<commit_after>/*
 * 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.controller.cluster.datastore.messages;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import akka.actor.ExtendedActorSystem;
import akka.testkit.javadsl.TestKit;
import java.io.NotSerializableException;
import java.util.List;
import org.junit.Test;
import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
import org.opendaylight.controller.cluster.datastore.AbstractTest;
import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
import org.opendaylight.controller.cluster.datastore.modification.MergeModification;
import org.opendaylight.controller.cluster.datastore.modification.Modification;
import org.opendaylight.controller.cluster.datastore.modification.WriteModification;
import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;

/**
 * Unit tests for ReadyLocalTransactionSerializer.
 *
 * @author <NAME>
 */
public class ReadyLocalTransactionSerializerTest extends AbstractTest {

    @Test
    public void testToAndFromBinary() throws NotSerializableException {
        DataTree dataTree = new InMemoryDataTreeFactory().create(
            DataTreeConfiguration.DEFAULT_OPERATIONAL, TestModel.createTestContext());
        DataTreeModification modification = dataTree.takeSnapshot().newModification();

        ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
        new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
        MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
        new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);

        TransactionIdentifier txId = nextTransactionId();
        ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);

        final ExtendedActorSystem system = (ExtendedActorSystem) ExtendedActorSystem.create("test");
        final Object deserialized;
        try {
            final ReadyLocalTransactionSerializer serializer = new ReadyLocalTransactionSerializer(system);
            final byte[] bytes = serializer.toBinary(readyMessage);
            deserialized = serializer.fromBinary(bytes, ReadyLocalTransaction.class);
        } finally {
            TestKit.shutdownActorSystem(system);
        }

        assertNotNull("fromBinary returned null", deserialized);
        assertEquals("fromBinary return type", BatchedModifications.class, deserialized.getClass());
        BatchedModifications batched = (BatchedModifications)deserialized;
        assertEquals("getTransactionID", txId, batched.getTransactionId());
        assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, batched.getVersion());

        List<Modification> batchedMods = batched.getModifications();
        assertEquals("getModifications size", 2, batchedMods.size());

        Modification mod = batchedMods.get(0);
        assertEquals("Modification type", WriteModification.class, mod.getClass());
        assertEquals("Modification getPath", TestModel.TEST_PATH, ((WriteModification)mod).getPath());
        assertEquals("Modification getData", writeData, ((WriteModification)mod).getData());

        mod = batchedMods.get(1);
        assertEquals("Modification type", MergeModification.class, mod.getClass());
        assertEquals("Modification getPath", TestModel.OUTER_LIST_PATH, ((MergeModification)mod).getPath());
        assertEquals("Modification getData", mergeData, ((MergeModification)mod).getData());
    }
}

{'fraction_non_alphanumeric': 0.09727538842603017, 'fraction_numerical': 0.0024769196126998424, 'mean_word_length': 5.046970728386658, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7596318', 'n_tokens_mistral': 2425, 'n_tokens_neox': 2347, 'n_words': 424}